//
//  GalleryScrollView.m
//  ios_news
//
//  Created by Han on 14-6-12.
//  Copyright (c) 2014年 ucoder. All rights reserved.
//

#import "GalleryScrollView.h"

@implementation GalleryScrollView


- (id) initWithFrame:(CGRect)frame :(UIView *)superView
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.showsHorizontalScrollIndicator = NO;
        self.pagingEnabled = YES;
        //self.backgroundColor = [UIColor greenColor];
        
        [self drawView:superView];
    }
    
    return self;
}


- (void) drawView :(UIView *)superView
{
    
    for (int i = 0; i < 3; i++) {
        UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[[NSString alloc] initWithFormat:@"%d.png", i]]];
        [img setFrame:CGRectMake(320 * i, 0, 320, 160)];
        [self addSubview:img];
    }
    
    // 必须给出内容的实际大小，滚动视图才知道滚动的范围
    self.contentSize = CGSizeMake(320 * 3, 160);
    
    
    [superView addSubview:self];
    
    UIPageControl *page = [[UIPageControl alloc] init];
    //[page addTarget:self action:@selector(turnPage) forControlEvents:UIControlEventValueChanged];
    //if ([_imageArray count] > 1) {
        // page.numberOfPages = _imageArray.count;
        //[self scrollRectToVisible:CGRectMake(320, 0, 320, 160) animated:NO];
        //self.scrollEnabled = YES;
        page.numberOfPages = 3;
        page.currentPage = 0;
        page.enabled = YES;
    //}
    //page.currentPage = 0;
    //page.enabled = YES;
    page.currentPageIndicatorTintColor = [UIColor whiteColor];
    page.pageIndicatorTintColor = [UIColor darkGrayColor];
    page.center = CGPointMake(160, self.frame.size.height*0.9);
    
    [superView addSubview:page];
}



@end
